<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>onerror事件</title>
    <script>
        onerror = handleErr;
        var txt = "";
        function handleErr(msg, url, l) {
            txt = "该页面有一个错误\n\n";
            txt += "错误: " + msg + "\n";
            txt += "URL: " + url + "\n";
            txt += "行: " + l + "\n\n";
            txt += "点击确定继续。\n\n";
            alert(txt);
            return true;
        }
        function message() {
            adddlert("Welcome guest!");
        }
    </script>
</head>

<body>
    <input type="button" value="查看消息" onclick="message()" />
</body>

</html>